package com.kele.store;

import com.kele.clinet.DeviceConfig;

import java.net.SocketAddress;
import java.util.concurrent.ConcurrentHashMap;

public class DeviceConfigStorage {

    private static final ConcurrentHashMap<String, DeviceConfig> storage = new ConcurrentHashMap<>();

    private DeviceConfigStorage(){}

    public static DeviceConfig get(SocketAddress address){
        String key = address.toString();
        return storage.get(key);
    }

    public static void put(DeviceConfig deviceConfig){
        String key = getKey(deviceConfig.getHostname(), deviceConfig.getHost());
        storage.put(key, deviceConfig);
    }

    public static void put(String key, DeviceConfig deviceConfig){
        storage.put(key, deviceConfig);
    }

    private static String getKey(String address, int host){
        return "/" + address + ":" + host;
    }

}
